package com.activiti.gateway;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.repository.DeploymentBuilder;
import org.activiti.engine.runtime.ProcessInstance;
import org.junit.Test;

/**
 * 流程变量测试
 * 
 * @author zhaoqx
 * 
 */
public class GatewayTest {
	ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();

	/**
	 * 部署流程定义
	 */
	@Test
	public void test1() {
		DeploymentBuilder deploymentBuilder = processEngine
				.getRepositoryService().createDeployment();
		deploymentBuilder
				.addClasspathResource("com/itheima/activiti/gateway/qjlc.bpmn");
		deploymentBuilder
				.addClasspathResource("com/itheima/activiti/gateway/qjlc.png");
		deploymentBuilder.deploy();
	}

	/**
	 * 启动流程实例时设置流程变量
	 */
	@Test
	public void test2() {
		String processDefinitionKey = "qjlc";// 流程定义key
		Map<String, Object> variables = new HashMap<String, Object>();
		variables.put("qjts", 1);
		ProcessInstance pi = processEngine.getRuntimeService()
				.startProcessInstanceByKey(processDefinitionKey, variables);
		System.out.println(pi.getId());
	}
	
	/**
	 * 办理任务时设置流程变量
	 */
	@Test
	public void test3() {
		String taskId = "2405";//任务id
		Map<String, Object> variables = new HashMap<>();
		variables.put("qjts", 2);
		processEngine.getTaskService().complete(taskId, variables);
	}
	
}
